<%@ page language="java" import="java.util.*,com.ncp.model.biz.product.*,com.ncp.model.dao.*,com.ncp.model.entity.product.*" pageEncoding="utf-8"%>
<%@page import="com.ncp.model.entity.cart.CartBean,com.ncp.model.entity.product.*"%>
<jsp:useBean id="cartbean" scope="session" class="com.ncp.model.entity.cart.CartBean"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
int PageNow=1;
int showPages=5;
int size=2;
int PageSize = 16;
ArrayList listbasic = (ArrayList)request.getAttribute("listbasic");
ArrayList listsort = (ArrayList)request.getAttribute("listsort");
String search = (String)request.getAttribute("search");
String name = (String)request.getAttribute("name");
String SortName = (String)request.getAttribute("SortName");
String order = (String)request.getAttribute("order");
if(search==null){
	search="all";
	
}
if(name==null){
	name="all";
	
}
if(SortName==null){
	SortName="";
	
}
if(order==null){
	order="all";
	
}
PageNow = Integer.parseInt((String)request.getAttribute("PageNow"));
int PageCount = Integer.parseInt((String)request.getAttribute("PageCount"));

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<base href="<%=basePath%>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>农产品</title>
<link href="css/common.css" type="text/css" rel="stylesheet" />
<link href="css/item.css" type="text/css" rel="stylesheet" />
<script src="js/cart/cart.js" type="text/javascript" charset="UTF-8"></script>

</head>

<body>
<div id="allpage">
	
		<jsp:include flush="true" page="../index/head.jsp"></jsp:include>
		
	<div id="main">
		<div id="search">
		
		    <form style="float:left;" action="SearchProductServlet?type=search&name=search" method="post">
			<input name="search" type="text" style="width:360px; float:left; height:32px; border:1px solid #F38B28; line-height:32px; font-size:20px;" />
			<input type="submit" value="" style="width:74px; float:left; margin-left:10px; height:34px; background:url(images/absulote/button_4.png); cursor:pointer;" />
			</form>
			<div id="pic" style="float:right"></div>
			<div style="clear:both"></div>
		</div>
		
		<div id="sort">
			<div class="label">产品分类</div>
			<div class="green_bond"></div>
			<!--分类项目-->
			<ul class="clasify left">
							<li><a href="SearchProductServlet?type=sort&search=all&name=sort">全部产品</a><div style="clear:both"></div></li>
			
			    <%
			    for(int i=0;i<listsort.size()&&i<24;i++){
			    	
			    	ProductSortBean psb = (ProductSortBean)listsort.get(i);
			    
			    %>
				
				<li><a href="SearchProductServlet?type=sort&search=<%=psb.getProductSortID()%>&name=sort"><%=psb.getProductSortName()%></a><div style="clear:both"></div></li>
				<%
				}
			    %>
			
			</ul>
			<div style="clear:both"></div>
		</div>
		
		
		<div id="display">
			<div id="all_babies">
				<div id="hippo"></div>
				<div id="complex">
				
				<%
						if(search.equals("all")){
						%>
					<form action="#" method="post">
						<!--<input type="button" style="width:86px; height:20px; background:url(images/absulote/icon_3.png) no-repeat; cursor:pointer; margin:10px 0 0 10px;" />-->
						<p style="float:left; line-height:34px;">&emsp;&emsp;排序</p>
						<style>
						#change li ul{ position:absolute;}
						</style>
						
						<ul id="change" class="left">
							<li>
								<a class="default" href="#">默认排序</a>
								<ul>
									<li><a class="bcm" href="SearchProductServlet?type=order&way=RetailPrice&search=all">按价格排序&emsp;&uarr;</a></li>
									<li><a class="bcm" href="SearchProductServlet?type=order&way=RetailPrice desc&search=all">按价格排序&emsp;&darr;</a></li>
									<li><a class="bcm" href="SearchProductServlet?type=order&way=ProductDiscount&search=all">按折扣排序&emsp;&uarr;</a></li>
									<li><a class="bcm" href="SearchProductServlet?type=order&way=ProductDiscount desc&search=all">按折扣排序&emsp;&darr;</a></li>
									<li><a class="bcm" href="SearchProductServlet?type=order&way=SoldPNumber&search=all">按默认排序&emsp;&uarr;</a></li>
								</ul>
							</li>
						</ul>
						
					</form>
					<%
						}else if(SortName!=null){
						%>
						<form action="#" method="post">
						<!--<input type="button" style="width:86px; height:20px; background:url(images/absulote/icon_3.png) no-repeat; cursor:pointer; margin:10px 0 0 10px;" />-->
						<p style="float:left; line-height:34px;">&emsp;&emsp;排序</p>
						<style>
						#change li ul{ position:absolute;}
						</style>
						
						<ul id="change" class="left">
							<li>
								<a class="default" href="SearchProductServlet?type=ordersort&way=RetailPrice&search=<%=search %>&SortName=<%=SortName %>">默认排序</a>
								<ul>
									<li><a class="bcm" href="SearchProductServlet?type=ordersort&way=RetailPrice&search=<%=search %>&SortName=<%=SortName %>">按价格排序&emsp;&uarr;</a></li>
									<li><a class="bcm" href="SearchProductServlet?type=ordersort&way=RetailPrice desc&search=<%=search %>&SortName=<%=SortName %>">按价格排序&emsp;&darr;</a></li>
									<li><a class="bcm" href="SearchProductServlet?type=ordersort&way=ProductDiscount&search=<%=search %>&SortName=<%=SortName %>">按折扣排序&emsp;&uarr;</a></li>
									<li><a class="bcm" href="SearchProductServlet?type=ordersort&way=ProductDiscount desc&search=<%=search %>&SortName=<%=SortName %>">按折扣排序&emsp;&darr;</a></li>
									<li><a class="bcm" href="SearchProductServlet?type=ordersort&way=SoldPNumber&search=<%=search %>&SortName=<%=SortName %>">按默认排序&emsp;&uarr;</a></li>
								</ul>
							</li>
						</ul>
						
					</form>
					
			<%} 
			else {
						%>
						
						<form action="#" method="post">
				<p style="float:left; line-height:34px;">&nbsp;&emsp;&emsp;搜索到的结果是：</p>
			</form>
			<%} %>
				</div>
			</div>
			
			
			<script>
				$('')
			</script>
			
			
			<div id="items">
				
				<div class="line">
				
				  <%     
				   if(listbasic!=null){
					
				
						for(int i=0;i<16&&i<listbasic.size();i++){
							ProductBasicBean pbb = (ProductBasicBean)listbasic.get(i);
							
						%>
				
					<div class="mix left">
						<div class="picture">
							<a href="ManageFrontzDetailProductServlet?ProductID=<%=pbb.getProductID()%>">
								<img src="<%=basePath+pbb.getProductImage()%>" /><%
								
								%>
							</a>
						</div>
						
						<div class="detail">
							<p>
								<span class="info_font"><%=pbb.getProductName()%></span>
								<span class="trade_font right">最近成交<%=pbb.getSoldPNumber()%>笔</span>
							</p>
							<p>
								<span class="gray_font">￥</span>
								<span class="red_font"><%=pbb.getRetailPrice() %></span>
								<span class="gray_font">￥<%=pbb.getMarketPrice() %></span>
								<span class="gray_font right">运费0.0</span>
							</p>
							
							<p class="buy">
								<input type="button" style="width:88px; height:20px; background:url(images/absulote/button_5.png); cursor:pointer;" onclick="addProductFromProductItem('<%=pbb.getProductID()%>')" />
							</p>
						</div>
						</div>
					
					<%} %><%
					 if(16>(listbasic.size())){
           	     for(int i=listbasic.size();i<PageSize;i++){
					%>
					
			   <div class="mix left">
						</div>

					

					<%
           	     }
				}
				}else {
					
				%>
					还没有任何商品上架！
				<% 
				}
					%>
				
					
					<div style="clear:both">  </div>
				</div>
				
			</div>
		</div>
			<div id="page">
					<ul>
					
					<% 
					if(PageCount>1){
					
					if(PageNow>1){
						%>
							<li><a  href="SearchProductServlet?type=FenYe&PageNow=<%=PageNow-1%>&order=<%=order %>&search=<%=search%>&name=<%=name%>&SortName=<%=SortName%>" class="page" ">上一页</a></li>
						
						
						<%
					}
					  
					
						if(PageCount>=showPages){
							if(PageNow-size<=0){
								for(int i=1;i<=showPages;i++){
									%>
									
									<li><a href="SearchProductServlet?type=FenYe&PageNow=<%=i%>&order=<%=order %>&search=<%=search%>&name=<%=name%>&SortName=<%=SortName %>" class="num" ><%=i%></a></li>
									<%
								}
								%><li>...</li><%
							}else if(PageNow+size<PageCount){
								for(int i=PageNow-size;i<=PageNow+size;i++){
									%>
									
									<li><a href="SearchProductServlet?type=FenYe&PageNow=<%=i%>&order=<%=order %>&search=<%=search%>&name=<%=name%>&SortName=<%=SortName %>" class="num" ><%=i%></a></li>
									<%
								}
								%><li>...</li><%
							}else if(PageNow+size>=PageCount){
								for(int i=PageCount-showPages+1;i<=PageCount;i++){
									%>
									
									<li><a href="SearchProductServlet?type=FenYe&PageNow=<%=i%>&order=<%=order %>&search=<%=search%>&name=<%=name%>&SortName=<%=SortName %>" class="num" ><%=i %></a></li>
									<%
								}
							}
							
						}else if(PageCount<=showPages){
							for(int i=1;i<=PageCount;i++){
								%>
								<li><a href="SearchProductServlet?type=FenYe&PageNow=<%=i%>&order=<%=order %>&search=<%=search%>&name=<%=name%>&SortName=<%=SortName %>" class="num" ><%=i %></a></li>
								<%
							}
						}
						if(PageNow<PageCount){
							%>
							<li><a  href="SearchProductServlet?type=FenYe&PageNow=<%=PageNow+1%>&order=<%=order %>&search=<%=search%>&name=<%=name%>&SortName=<%=SortName %>" class="page" ">下一页</a></li>
							<%
						}
						
						%>
						<li>共<%= PageCount%>页&emsp;</li>
							
							
							
							  <form style="display:inline;" action="SearchProductServlet?order=<%=order %>&type=FenYe&search=<%=search%>&name=<%=name%>&SortName=<%=SortName %>" method="post"><input type="text" style="width:30px; border:1px solid #CCC;" name="PageNow"/>&emsp;页
            </form>
						
					</ul>
<%
					}
%>
		</div>
	</div>
	
	
	
	
	<div id="slice">
	</div>
	
		<jsp:include flush="true" page="../index/foot.jsp"></jsp:include>
</div>
</body>
</html>
